﻿<UserControl x:Class="ComicTool.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
             xmlns:dark="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.ExpressionDark"
             xmlns:local="clr-namespace:ComicTool"
             mc:Ignorable="d"
             xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
             xmlns:toolKit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
             xmlns:it="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"
             AllowDrop="True"
             d:DesignWidth="529"
             d:DesignHeight="481">
    <UserControl.Resources>
        <local:NullVisibilityConverter x:Key="NullVisibilityConverter" />
        <local:FalseVisibilityConverter x:Key="FalseVisibilityConverter" />
    </UserControl.Resources>
    <dark:ExpressionDarkTheme>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition To="Show"
                                      GeneratedDuration="0:0:0.3" />
                    <VisualTransition To="Hide"
                                      GeneratedDuration="0:0:0.6" />
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Show">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="ClickArea"
                                         Storyboard.TargetProperty="Opacity"
                                         To="1" />
                        <DoubleAnimation Storyboard.TargetName="ClickArea1"
                                         Storyboard.TargetProperty="Opacity"
                                         To="1" />
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Hide">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="ClickArea"
                                         Storyboard.TargetProperty="Opacity"
                                         To="0" />
                        <DoubleAnimation Storyboard.TargetName="ClickArea1"
                                         Storyboard.TargetProperty="Opacity"
                                         To="0" />
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <toolKit:ContextMenuService.ContextMenu>
            <toolKit:ContextMenu>
                <toolKit:MenuItem Header="Next (Space, Ctrl + Right Arrow)"
                                  Command="{Binding NextCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Next_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:MenuItem Header="Previous (Ctrl + Left Arrow)"
                                  Command="{Binding PreviousCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Previous_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:Separator />
                <toolKit:MenuItem Header="Auto Size (Ctrl + Alt + A)"
                                  Click="Button_Click_3">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Undo_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:MenuItem Header="Zoom In (Ctrl + Up Arrow)"
                                  Click="Button_Click_4">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Zoom In_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:MenuItem Header="Zoom Out (Ctrl + Down Arrow)"
                                  Click="Button_Click_5">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Zoom Out_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:Separator />
                <toolKit:MenuItem Header="Open URL (Ctrl + Alt + O)"
                                  Command="{Binding OpenURLCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Globe_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:MenuItem Header="Open Local File"
                                  Command="{Binding OpenFileCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Open_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:Separator />
                <toolKit:MenuItem Header="Delete Page"
                                  Command="{Binding DeleteCurrentPageCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Delete_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:MenuItem Header="Edit/Undelete Pages (Ctrl + Alt + E)"
                                  Command="{Binding EditComicCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Edit_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:Separator />
                <toolKit:MenuItem Header="Save Original Comic File"
                                  Command="{Binding SaveOriginalCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Save_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:MenuItem Header="Export as CBZ"
                                  Command="{Binding SaveCBZCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Save_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:MenuItem Header="Export as PDF"
                                  Command="{Binding SavePDFCommand}">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Save_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
                <toolKit:Separator />
                <toolKit:MenuItem Header="Install Out of Browser"
                                  Command="{Binding InstallCommand}">
                </toolKit:MenuItem>
                <toolKit:Separator />
                <toolKit:MenuItem Header="About"
                                  Click="Button_Click_7">
                    <toolKit:MenuItem.Icon>
                        <Image Source="/ComicTool;component/Icons/Information_48x48.png"
                               Height="16"
                               Width="16" />
                    </toolKit:MenuItem.Icon>
                </toolKit:MenuItem>
            </toolKit:ContextMenu>
        </toolKit:ContextMenuService.ContextMenu>
        <Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <TextBlock VerticalAlignment="Center"
                       HorizontalAlignment="Center"
                       Width="400"
                       TextWrapping="Wrap"
                       Visibility="{Binding Comic.CurrentPage, Converter={StaticResource NullVisibilityConverter}}"><Run Text="Open a CBR/CBZ in four ways: " /><LineBreak /><Run Text="- OpenURL " /><LineBreak /><Run Text="- Open Local File " /><LineBreak /><Run Text="- Drag a file from your local machine onto this page " /><LineBreak /><Run Text="- Querystring variable 'c' to load a url that is urlencoded. This is useful for static links from a webpage. (e.g. comictool.html?c=http...) " /><LineBreak /><Run Text=" " /><LineBreak /><Run Text="All actions are in right click menu or appear when mouse near at the bottom." /></TextBlock>
            <local:ImageEditorContainerEx  x:Name="Container"
                                           ScalingMode="{Binding ScalingMode}"
                                           Scaling="{Binding Scaling}"
                                           Source="{Binding Comic.CurrentPage.Image}"
                                           CanvasItems="{Binding Comic.CurrentPage.Paths}"/>
            <Border x:Name="Pages"
                    VerticalAlignment="Top"
                    MouseLeave="grid_MouseLeave"
                    MouseEnter="grid_MouseEnter"
                    Background="#00000000">
                <Grid x:Name="ClickArea1"
                      VerticalAlignment="Bottom"
                      HorizontalAlignment="Center">
                    <Border BorderBrush="#FF524949"
                            BorderThickness="1"
                            CornerRadius="10"
                            HorizontalAlignment="Center"
                            Grid.Row="1"
                            VerticalAlignment="Center"
                            Margin="5"
                            Padding="5"
                            Background="Black">
                        <ListBox ItemsSource="{Binding Comic.Pages}"
                                 SelectedItem="{Binding Comic.CurrentPage, Mode=TwoWay}"
                                 ItemsPanel="{StaticResource ComicPageListBoxPanel}"
                                 ItemTemplate="{StaticResource ComicPageListBoxItem}" />
                    </Border>
                </Grid>
            </Border>
            <Border x:Name="NavArea"
                    Height="150"
                    VerticalAlignment="Bottom"
                    MouseLeave="grid_MouseLeave"
                    MouseEnter="grid_MouseEnter"
                    Background="#00000000">
                <Grid x:Name="ClickArea"
                      VerticalAlignment="Bottom"
                      HorizontalAlignment="Center">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Border BorderBrush="#FF524949"
                            BorderThickness="1"
                            CornerRadius="10"
                            HorizontalAlignment="Center"
                            Grid.Row="1"
                            VerticalAlignment="Center"
                            Margin="5"
                            Padding="5"
                            Background="Black">
                        <Grid x:Name="grid"
                              Background="Black">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="Current Comic: "
                                       Margin="5"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center" />
                            <TextBlock Text="{Binding Comic.Title}"
                                       Margin="5"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       Grid.Column="1" />
                            <TextBlock Text="Viewing Page: "
                                       Margin="5"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       Grid.Column="2" />
                            <TextBlock Text="{Binding Comic.ViewingIndex}"
                                       Margin="5"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       Grid.Column="3" />
                        </Grid>
                    </Border>
                    <Border x:Name="Menu"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Bottom"
                            BorderBrush="#FF524949"
                            BorderThickness="1"
                            CornerRadius="32"
                            Padding="16,5"
                            Background="Black">
                        <StackPanel Orientation="Horizontal"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Center">
                            <Button Margin="5"
                                    Command="{Binding PreviousCommand}">
                                <Image Source="/ComicTool;component/Icons/Previous_48x48.png" />
                            </Button>
                            <Button Margin="5"
                                    Command="{Binding NextCommand}">
                                <Image Source="/ComicTool;component/Icons/Next_48x48.png" />
                            </Button>
                            <Button Margin="5"
                                    Click="Button_Click_3">
                                <Image Source="/ComicTool;component/Icons/Undo_48x48.png" />
                            </Button>
                            <Button Margin="5"
                                    Click="Button_Click_4">
                                <Image Source="/ComicTool;component/Icons/Zoom In_48x48.png" />
                            </Button>
                            <Button Margin="5"
                                    Click="Button_Click_5">
                                <Image Source="/ComicTool;component/Icons/Zoom Out_48x48.png" />
                            </Button>
                            <Button Margin="5"
                                    Command="{Binding OpenURLCommand}">
                                <Image Source="/ComicTool;component/Icons/Globe_48x48.png" />
                            </Button>
                            <Button Margin="5"
                                    Command="{Binding OpenFileCommand}">
                                <Image Source="/ComicTool;component/Icons/Open_48x48.png" />
                            </Button>
                            <Button Margin="5"
                                    Click="Button_Click_7">
                                <Image Source="/ComicTool;component/Icons/Information_48x48.png" />
                            </Button>
                        </StackPanel>
                    </Border>
                </Grid>
            </Border>           
            <Border Visibility="{Binding Comic.CurrentPage.IsLoaded, Converter={StaticResource FalseVisibilityConverter}, FallbackValue=Collapsed}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Width="300"
                    Background="Black"
                    BorderBrush="#FF524949"
                    BorderThickness="1"
                    CornerRadius="10">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="Loading Page..."
                               Margin="5"
                               VerticalAlignment="Center" />
                    <ProgressBar Height="10"
                                 Grid.Row="1"
                                 Maximum="100"
                                 IsIndeterminate="True"
                                 Margin="5"
                                 VerticalAlignment="Center" />
                </Grid>
            </Border>
            <Border Visibility="{Binding ProgressVisilibity}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Width="300"
                    Background="Black"
                    BorderBrush="#FF524949"
                    BorderThickness="1"
                    CornerRadius="10">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock x:Name="progressText"
                               Text="{Binding ProgressText}"
                               Margin="5"
                               VerticalAlignment="Center" />
                    <ProgressBar x:Name="progressBar"
                                 Height="10"
                                 Grid.Row="1"
                                 Maximum="100"
                                 Value="{Binding ProgressPercent}"
                                 IsIndeterminate="{Binding ProgressIndeterminate}"
                                 Margin="5"
                                 VerticalAlignment="Center" />
                </Grid>
            </Border>
        </Grid>
    </dark:ExpressionDarkTheme>
</UserControl>
